﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace cadbom
{
    public partial class SetObjectForm : Form
    {
        //private System.Windows.Forms.Timer timer;
        //private int searchDelay = 500; // 设置延时，单位毫秒
        NetApi netApi = new NetApi();
        private System.Data.DataTable dtBand = null;
        public SetObjectForm()
        {
            InitializeComponent();

            //timer = new System.Windows.Forms.Timer();
            //timer.Interval = searchDelay;
            //timer.Tick += new EventHandler(Timer_Tick);
        }

        private void SetObjectForm_Load(object sender, EventArgs e)
        {

        }
        //保存数据
         private void button9_Click(object sender, EventArgs e)
        {

        }

        //选择物料
        private void button7_Click(object sender, EventArgs e)
        {

        }
        //移除
        private void button6_Click(object sender, EventArgs e)
        {

        }
        //添加
        private void button5_Click(object sender, EventArgs e)
        {

        }
        //查询产品信息
        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
            {
                netApi.getProductData(textBox1.Text.Trim(), new Action<BasProduct>((product) =>
                {
                    this.textBox2.Text = product.custId_dictText;
                    this.textBox7.Text = product.productType_dictText;
                    this.textBox16.Text = product.code;
                    this.textBox3.Text = product.custCode;
                    this.textBox8.Text = product.drawingNo;
                    this.textBox15.Text = product.stage_dictText;
                    this.textBox4.Text = product.name;
                    this.textBox9.Text = product.productVer == null ? "" : product.productVer;
                    this.textBox14.Text = product.unitId_dictText;
                }));
            }
        }
        private void initDataGridView(String productId)
        {
            netApi.getProductBom(productId, new Action<List<ProductBomTree>>((items) =>
            {
                //initProcessBomView();
                dtBand = new System.Data.DataTable();

                dtBand.Columns.Add("code");
                dtBand.Columns.Add("name");
                dtBand.Columns.Add("drawingNo");
                dtBand.Columns.Add("description");
                dtBand.Columns.Add("version");
                dtBand.Columns.Add("qty");
                dtBand.Columns.Add("unitId_dictText");
                dtBand.Columns.Add("typeName");
                dtBand.Columns.Add("id");
                dtBand.Columns.Add("pid");
                foreach (ProductBomTree mpb in items)
                {
                    DataRow dr = dtBand.NewRow();
                    dr["code"] = mpb.code;
                    dr["name"] = mpb.name;
                    dr["drawingNo"] = mpb.drawingNo;
                    dr["description"] = mpb.description;
                    dr["version"] = mpb.version;
                    dr["qty"] = mpb.qty;
                    dr["unitId_dictText"] = mpb.unitId_dictText;
                    dr["typeName"] = mpb.typeName;
                    dr["id"] = mpb.id;
                    dr["pid"] = mpb.pid;
                    dtBand.Rows.Add(dr);
                }
                this.dataGridView1.DataSource = dtBand;
                dataGridView1.Columns["code"].HeaderText = "物料编码";
                dataGridView1.Columns["name"].HeaderText = "物料名称";
                dataGridView1.Columns["drawingNo"].HeaderText = "物料规格";
                dataGridView1.Columns["description"].HeaderText = "物料描述";
                dataGridView1.Columns["version"].HeaderText = "版本";
                dataGridView1.Columns["qty"].HeaderText = "数量";
                dataGridView1.Columns["unitId_dictText"].HeaderText = "单位";
                dataGridView1.Columns["typeName"].HeaderText = "物料类型";
                this.dataGridView1.Columns["id"].Visible = false;
                this.dataGridView1.Columns["pid"].Visible = false;
            }));
        }
        //产品输入框文本变化
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            //timer.Stop();
            //timer.Start();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
        //private void Timer_Tick(object sender, EventArgs e)
        //{
        //    timer.Stop();
        //    // 在这里编写查找逻辑
        //    PerformSearch(textBox1.Text);
        //}
        //private void PerformSearch(string searchText)
        //{
        //    // 执行查找操作
        //}
    }
}
